package com.gsoc.spreadsheet.client;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.ui.Panel;
import com.google.gwt.user.client.Command;
import com.google.gwt.user.client.ui.MenuBar;
import com.google.gwt.user.client.ui.DockPanel;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.ClickListener;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;
import com.google.gwt.user.client.ui.Grid;
import com.google.gwt.user.client.ui.TableListener;
import com.google.gwt.user.client.ui.SourcesTableEvents;

/**
 * Entry point classes define <code>onModuleLoad()</code>.
 */
public class Spreadsheet implements EntryPoint {

	private Aggregate spread;
	
	public Spreadsheet() {
		spread = new Aggregate();
	}
	
	public Spreadsheet(int size) {
		spread = new Aggregate(size);
	}
	
	public DockPanel view() {
		DockPanel panel = new DockPanel();
		
		//RootPanel.get().setSize("640px", "480px");
		Command cmd = new Command() {
			public void execute() {
				Window.alert("You selected a menu item!");
			}
		};

		// Make some sub-menus that we will cascade from the top menu.
		MenuBar fileMenu = new MenuBar(true);
		fileMenu.addItem("New", cmd);
		fileMenu.addItem("Open", cmd);

		MenuBar editMenu = new MenuBar(true);
		editMenu.addItem("the", cmd);
		editMenu.addItem("bar", cmd);
		editMenu.addItem("menu", cmd);

		// Make a new menu bar, adding a few cascading menus to it.
		MenuBar menu = new MenuBar();
		menu.addItem("File", fileMenu);
		menu.addItem("Edit", editMenu);
		menu.addItem("Search", cmd);

		// Add it to the root panel.
		panel.add(menu, DockPanel.NORTH);
		
		Panel view = spread.view();
		view.setWidth("800px");
		view.setHeight("600px");

		panel.add(view, DockPanel.SOUTH);
		
		return panel;
	}
	
	public void onModuleLoad() {
		
		Spreadsheet spread = new Spreadsheet(30);
		RootPanel.get().add(spread.view());
	}
}
